;; Test file for R4RS section 6.4 number procedures

;; Define a helper function to output a newline
(define (newline) (display "\n"))

(define (test-description description)
    (begin
        (display "Testing: ")
        (display description)
        (newline)))


;; Test odd? procedure
(test-description "odd? procedure")

(odd? 1)       ;; => #t
(odd? 2)       ;; => #f
(odd? 0)       ;; => #f
(odd? -1)      ;; => #t
(odd? -2)      ;; => #f
(odd? 1001)    ;; => #t
(odd? 1000)    ;; => #f

;; Test even? procedure
(test-description "even? procedure")

(even? 1)      ;; => #f
(even? 2)      ;; => #t
(even? 0)      ;; => #t
(even? -1)     ;; => #f
(even? -2)     ;; => #t
(even? 1001)   ;; => #f
(even? 1000)   ;; => #t

;; Test gcd procedure
(test-description "gcd procedure")

(gcd 12 8)     ;; => 4
(gcd 12 18)    ;; => 6
(gcd 13 17)    ;; => 1
(gcd 0 5)      ;; => 5
(gcd 5 0)      ;; => 5
(gcd -12 8)    ;; => 4
(gcd 12 -8)    ;; => 4
(gcd 120 84 36) ;; => 12

;; Test lcm procedure
(test-description "lcm procedure")

(lcm 12 8)     ;; => 24
(lcm 12 18)    ;; => 36
(lcm 13 17)    ;; => 221
(lcm 0 5)      ;; => 0
(lcm 5 0)      ;; => 0
(lcm -12 8)    ;; => 24
(lcm 12 -8)    ;; => 24
(lcm 4 6 8)    ;; => 24

;; Test with rational numbers
(test-description "Number procedures with rational numbers")

(odd? 3/2)     ;; => #f (3/2 is 1.5, not an integer)
(even? 4/2)    ;; => #t (4/2 is 2, an even integer)
(gcd 9/3 6/2)  ;; => 3
(lcm 9/3 6/2)  ;; => 6

;; Test error conditions
(test-description "Error conditions")

; These should raise errors due to non-integer arguments
(odd? 1.5)     ;; Error
(even? 1.5)    ;; Error
(gcd 12 8.5)   ;; Error
(lcm 12 8.5)   ;; Error

(test-description "All number procedure tests completed!")